//
//  SERegistrationHospitalViewModel.swift
//  SmartEyeForPatient
//
//  Created by qdsg on 2021/4/2.
//

import HandyJSON

class SERegistrationDeptViewModel: SEBaseViewModel {

    var models: [SERegistrationDeptModel] = []

    var hospitalModel = SEHospitalListItem()

    func deptModel(indexPath: IndexPath) -> SERegistrationDeptModel {
        return models[indexPath.row]
    }

    var selectDeptIndexPath = IndexPath(row: 0, section: 0)

    var childDeptModels: [SERegistrationDeptModel] {
        guard models.count > 0 else { return [] }
        return deptModel(indexPath: selectDeptIndexPath).child
    }

    func requestDeptData() {
        SEHttpManager.shared.requestForModelArray(SERegistrationAPI.departMentList(id: hospitalModel.id), model: SERegistrationDeptModel.self) { (models, status) in
            switch status {
            case .success:
                self.models = models ?? self.models
            default:
                break
            }
            self.updateData?(status)
        }
    }
}

struct SERegistrationDeptModel: HandyJSON {
    /**
     科室id
     */
    var id: String = ""
    /**
     科室名称
     */
    var name: String = ""
    /**
     二级科室
     */
    var child: [SERegistrationDeptModel] = []
}
